﻿using System;

namespace ESoft.Extensions
{
    public static class BooleanExtensions
    {
        /// <summary>
        /// 是否为false
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool IsFalse(this bool obj)
        {
            return obj == false;
        }
        /// <summary>
        /// 是否为true
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool IsTrue(this bool obj)
        {
            return obj == true;
        }

        /// <summary>
        /// 如果为真执行action
        /// </summary>
        /// <param name="this">if set to <c>true</c> [this].</param>
        /// <param name="action">The action.</param>
        public static void IfTrue(this bool @this, Action action)
        {
            if (@this) action();
        }

        /// <summary>
        /// 如果为假执行action
        /// </summary>
        /// <param name="this">if set to <c>true</c> [this].</param>
        /// <param name="action">The action.</param>
        public static void IfFalse(this bool @this, Action action)
        {
            if (!@this) action();
        }
        
        public static string ToString(this bool @this, string trueValue, string falseValue)
        {
            return @this ? trueValue : falseValue;
        }
    }
}
